/**
 * 安卓白金英雄坛制作组 <br>
 * 文件名：EditNameDialog.java <br>
 * 创建时间：2013-5-21 下午4:07:07 <br>
 * 所属项目：GmudEX <br>
 * @author 12548 <br>
 */
package lostland.gmud.exv2.ui.meta;

import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;

import lostland.gmud.exv2.Gmud;
import lostland.gmud.exv2.R;
import lostland.gmud.exv2.ui.NotificationScreen;

/**
 * 类名：EditNameDialog <br>
 * 说明：改名对话框
 *
 * @author 12548
 */
public class EditNameDialog extends Dialog {

	private Window mWindow;
	EditText etName;
	Button btnOK;

	/**
	 * @param context
	 */
	public EditNameDialog(Context context) {
		super(context);
		mWindow = getWindow();
		mWindow.setBackgroundDrawable(new ColorDrawable(0));
		mWindow.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
		WindowManager.LayoutParams lp = mWindow.getAttributes();
		lp.gravity = Gravity.CENTER;
		lp.dimAmount = 0.0001f;
		mWindow.setAttributes(lp);
		setCanceledOnTouchOutside(true);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		mWindow.setContentView(R.layout.dialog_changenickname);

		etName = (EditText) findViewById(R.id.etNickname);

		btnOK = (Button) findViewById(R.id.btnEditNickname);

		btnOK.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				String name = etName.getText().toString();
				if (Gmud.mc != null) {
					if (name.length() > 0) {
						Gmud.mc.name = name;
					} else {
						Gmud.mc.name = "无名氏";
					}

					if (Gmud.mc.name.length() > 8) {
						Gmud.mc.name = Gmud.mc.name.substring(0, 8);
					}
				}
				new NotificationScreen("角色姓名修改成功！").pushToGame();
			}
		});
	}

}
